package io.github.uicdb.liba.api.register.data;

import com.google.common.collect.Multimap;
import io.github.uicdb.liba.api.register.ItemHolder;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.tags.BlockTagsProvider;
import net.minecraft.data.tags.ItemTagsProvider;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;

public class LazyItemTagProvider extends ItemTagsProvider {
    private final Multimap<ItemHolder<?>, TagKey<Item>> map;
    private final HashMap<TagKey<Item>,TagKey<Item>> itemCopy;
    public LazyItemTagProvider(DataGenerator pGenerator, BlockTagsProvider pBlockTagsProvider, String modId, @Nullable ExistingFileHelper existingFileHelper, Multimap<ItemHolder<?>, TagKey<Item>> map,HashMap<TagKey<Item>,TagKey<Item>> itemCopy) {
        super(pGenerator, pBlockTagsProvider, modId, existingFileHelper);
        this.map = map;
        this.itemCopy=itemCopy;
    }

    @Override
    protected void addTags() {
        map.forEach((itemHolder, tagKey) -> LazyItemTagProvider.this.tag(tagKey).add(itemHolder.get()));
        itemCopy.forEach((from,to)->{
            LazyItemTagProvider.this.tag(to).addTag(from);
        });
    }
}
